package com.founder.devwork.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.devwork.dto.res.EngineerStatsDTO;
import com.founder.devwork.entity.Engineer;
import com.founder.devwork.persistence.mapper.EngineerMapper;
import com.founder.devwork.service.EngineerService;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * EngineerServiceImpl 用于实现 EngineerService 接口。
 * 提供查询工程师信息的方法。
 */
@Service
public class EngineerServiceImpl extends ServiceImpl<EngineerMapper, Engineer> implements EngineerService {

    /**
     * @inheritDoc
     */
    @Override
    public List<Engineer> listByDeptId(String deptId) {
        return this.lambdaQuery().eq(Engineer::getDeptId, deptId).list();
    }

    /**
     * @inheritDoc
     */
    @Override
    public IPage<EngineerStatsDTO> getEngineerStats(int page, int size, String department, String name, String sortBy, String sortDirection) {
        long total = baseMapper.countEngineerStats(department, name);
        List<EngineerStatsDTO> records = baseMapper.selectEngineerStats(department, name, sortBy, sortDirection, (page - 1) * size, size);
        Page<EngineerStatsDTO> result = new Page<>(page, size, total);
        result.setRecords(records);
        return result;
    }
}
